package com.dongdong.bookstore.module.ums.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dongdong.bookstore.module.ums.model.Resource;
import com.dongdong.bookstore.module.ums.mapper.ResourceMapper;
import com.dongdong.bookstore.module.ums.service.ResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 后台资源  服务实现类
 * </p>
 *
 * @author chiangkai
 * @since 2021-10-20
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {

    
    @Override
    public Page<Resource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum) {
        Page<Resource> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Resource> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<Resource> lambda = wrapper.lambda();
        if(categoryId!=null){
            lambda.eq(Resource::getCategoryId,categoryId);
        }
        if(StrUtil.isNotEmpty(nameKeyword)){
            lambda.like(Resource::getName,nameKeyword);
        }
        if(StrUtil.isNotEmpty(urlKeyword)){
            lambda.like(Resource::getUrl,urlKeyword);
        }
        return page(page,wrapper);
    }
}
